Ext.onReady(function() {

	var btn = new Ext.Button({
				renderTo	: Ext.getBody(),
				text		: 'pie chart',
				handler		: function() {
					pieWin.show(this.getEl());
				}
			});

	var btn2 = new Ext.Button({
				renderTo	: Ext.getBody(),
				text		: 'line chart',
				handler		: function() {
					lineWin.show(this.getEl());
				}
			});

	var btn3 = new Ext.Button({
				renderTo	: Ext.getBody(),
				text		: 'column chart',
				handler		: function() {
					columnWin.show(this.getEl());
				}
			});

	var btn4 = new Ext.Button({
				renderTo	: Ext.getBody(),
				text		: 'xy chart',
				handler		: function() {
					xyWin.show(this.getEl());
				}
			});

	/* --------------------------- window ------------------------- */

	var pieWin = new Ext.Window({
		title		: 'pie chart',
		closeAction	: 'hide',
		maximizable	: true,
		width		: 500,
		height		: 350,
		html		: '<div id="pie-chart"><strong>You need to upgrade your Flash Player</strong></div>',
		listeners	: {
			'resize'	: function() {
				show('pie-chart', 'pie');
			}
		}
	}
	);

	var lineWin = new Ext.Window({
		title		: 'line chart',
		closeAction	: 'hide',
		maximizable	: true,
		width		: 500,
		height		: 350,
		html		: '<div id="line-chart"><strong>You need to upgrade your Flash Player</strong></div>',
		listeners	: {
			'resize'	: function() {
				show('line-chart', 'line');
			}
		}
	}
	);

	var columnWin = new Ext.Window({
		title		: 'column chart',
		closeAction	: 'hide',
		maximizable	: true,
		width		: 500,
		height		: 350,
		html		: '<div id="column-chart"><strong>You need to upgrade your Flash Player</strong></div>',
		listeners	: {
			'resize'	: function() {
				show('column-chart', 'column');
			}
		}
	}
	);

	var xyWin = new Ext.Window({
		title		: 'xy chart',
		closeAction	: 'hide',
		maximizable	: true,
		width		: 500,
		height		: 350,
		html		: '<div id="xy-chart"><strong>You need to upgrade your Flash Player</strong></div>',
		listeners	: {
			'resize'	: function() {
				show('xy-chart', 'xy');
			}
		}
	}
	);

	/* --------------------------- utils ------------------------- */

	function show(id, type) {
		var so = new SWFObject("../../script/amcharts/am" + type + ".swf", id,
				'100%', '100%', "9", "#FFFFFF"
		);
		so.addVariable("path", "../../script/amcharts/"); // for license location
		so.addVariable("settings_file", encodeURIComponent("../charts/" + type
						+ "-settings.xml"));
		// so.addVariable("data_file", encodeURIComponent("./charts/" + type + "-data.xml"));
		so.addVariable("data_file", encodeURIComponent(type + '-data.xml'));
		so.write(id);
	}
}
);